package com.hlkj.pay.infrastructure.model.merchant;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.hlkj.framework.common.util.json.JsonUtils;
import com.hlkj.framework.mybatis.core.dataobject.BaseDO;
import com.hlkj.pay.dto.merchant.MerchantLimitPaymentDto;
import com.hlkj.pay.dto.merchant.ProviderChannelFeeConfigList;
import com.hlkj.pay.dto.merchant.config.MerchantPaymentConfigDto;
import com.hlkj.pay.dto.merchant.config.MerchantReportConfigDto;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.springframework.util.StringUtils;

import java.util.List;

/**
* 商户配置表
* @TableName t_merchant_config
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true)
@TableName("t_merchant_config")
public class MerchantConfigDO extends BaseDO {
    /**
    * 商户商户号
    */
    private String sn;
    /**
    * 费率配置
    */
    private String feeConfig;
    /**
    * 默认服务商
    */
    private String providerCode;
    /**
    * 默认通道
    */
    private String channelCode;
    /**
    * 代付配置
    */
    private String paymentConfig;
    /**
    * 代付配置
    */
    private String reportConfig;
    /**
     * 代付配置
     */
    private String limitConfig;

    @TableField(exist = false)
    private List<String> providerCodeList;
    @TableField(exist = false)
    private List<String> channelCodeList;
    @TableField(exist = false)
    private List<ProviderChannelFeeConfigList> merchantFeeConfigList;
    @TableField(exist = false)
    private MerchantLimitPaymentDto merchantLimitPaymentDto;
    /**
     * 代付配置
     */
    @TableField(exist = false)
    private MerchantPaymentConfigDto merchantPaymentConfigDto;
    /**
     * 代付配置
     */
    @TableField(exist = false)
    private MerchantReportConfigDto merchantReportConfigDto;
    public List<String> getProviderCodeList() {
        if(this.providerCodeList!=null){
            return this.providerCodeList;
        }
        if(StringUtils.hasText(providerCode)){
            setProviderCodeList(JsonUtils.parseArray(providerCode, String.class));
        }
        
        return this.providerCodeList;
    }
    public List<String> getChannelCodeList() {
        if(this.channelCodeList!=null){
            return this.channelCodeList;
        }
        if(StringUtils.hasText(channelCode)){
            setChannelCodeList(JsonUtils.parseArray(channelCode, String.class));
        }
        
        return this.channelCodeList;
    }
    public List<ProviderChannelFeeConfigList> getMerchantFeeConfigList() {
        if(this.merchantFeeConfigList!=null){
            return this.merchantFeeConfigList;
        }
        if(StringUtils.hasText(feeConfig)){
            setMerchantFeeConfigList(JsonUtils.parseArray(feeConfig, ProviderChannelFeeConfigList.class));
        }
        
        return this.merchantFeeConfigList;
    }

    public MerchantPaymentConfigDto merchantPaymentConfig(){
        if(this.merchantPaymentConfigDto !=null){
            return this.merchantPaymentConfigDto;
        }
        if(StringUtils.hasText(paymentConfig)){
            setMerchantPaymentConfigDto(JsonUtils.parseObject(paymentConfig, MerchantPaymentConfigDto.class));
        }

        return this.merchantPaymentConfigDto;
    }
    public MerchantReportConfigDto merchantReportConfig(){
        if(this.merchantReportConfigDto !=null){
            return this.merchantReportConfigDto;
        }
        if(StringUtils.hasText(reportConfig)){
            setMerchantReportConfigDto(JsonUtils.parseObject(reportConfig, MerchantReportConfigDto.class));
        }

        return this.merchantReportConfigDto;
    }

    public MerchantLimitPaymentDto merchantLimitPaymentDto(){
        if(this.merchantLimitPaymentDto !=null){
            return this.merchantLimitPaymentDto;
        }
        if(StringUtils.hasText(limitConfig)){
            setMerchantLimitPaymentDto(JsonUtils.parseObject(limitConfig, MerchantLimitPaymentDto.class));
        }

        return this.merchantLimitPaymentDto;
    }
}
